package k.daniel.databindingdemo.model;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class ActivityModel extends BaseObservable {
    ActivityInfo activityInfo;
    public ActivityModel(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
//        this.name=name;
    }
//    String name;
    @Bindable
    public String getName()
    {
        return activityInfo.name;
    }
    public void onClick(View v)
    {
        Intent intent = new Intent();
        intent.setClassName(v.getContext(),activityInfo.name);
        v.getContext().startActivity(intent);
    }

    public static List<ActivityModel> parse(ActivityInfo[] activities)
    {
        List<ActivityModel> models = new ArrayList<ActivityModel>();
        for (ActivityInfo ac :activities) {
            models.add(new ActivityModel(ac));
        }
        return models;
    }


}
